<?php
/**
 * Supplier Stock Out Head
 */
class SSoH extends AppModel {
    var $name = 'SSoH';

    var $useTable = 'supplier_stock_out_heads';

    var $belongsTo = array(
            'Supplier', 'Customer', 'Site',
            'User' => array(
                'fields' => array('username', 'name')
        )
    );

    var $hasMany = array(
        'SSo' => array(
            'dependent'    => true
        )
    );

    var $validate = array(
            'stock_out_no' => array(
                        'rule' => array('notEmpty'),
                        'message' => 'Stock out no. is required.',
                        'required' => true,
        ),
            'stock_out_date' => array(
                        'rule' => array('notEmpty'),
                        'message' => 'Stock out date is required.',
                        'required' => true,
        ),
            'stock_out_by' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Stock out by is required.',
                    'required' => true,
        ),
            'supplier_id' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Supplier is required.',
                    'required' => true,
        ),
            'customer_id' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Customer is required.',
                    'required' => true,
        ),
            'site_id' => array(
                    'rule' => 'notEmpty',
                    'message' => 'Site is required.',
                    'required' => true,
        ),
    );

    function beforeSave() {
        // Outsert
        if (isset($this->data['SSoH']['stock_out_date'])) {
            $this->data['SSoH']['stock_out_date'] = $this->dateFormatBeforeSave($this->data['SSoH']['stock_out_date']);
        }
        return true;
    }

    function afterFind($results) {
        foreach ($results as &$SSoH) {
            if (isset($SSoH['SSoH']['stock_out_date'])) {
                $SSoH['SSoH']['stock_out_date'] = $this->dateFormatAfterFind($SSoH['SSoH']['stock_out_date']);
            }

        }
        return $results;
    }
}
?>
